﻿Public Class ctl_U3DI_Status
    Public Event PortSelected(ByVal PortID As Integer)
    Private ShowDescription As Boolean = False
    Private _Status As Boolean()
    Public Property Status() As Boolean()
        Get
            Return _Status
        End Get
        Set(ByVal value As Boolean())
            _Status = value
            Try
                UpdateStatus()
            Catch
            End Try
        End Set
    End Property

    Private _Config As DataSet
    Public Property Config() As DataSet
        Get
            Return _Config
        End Get
        Set(ByVal value As DataSet)
            _Config = value
        End Set
    End Property

    Public Property pSerialNumber() As String
        Get
            Return lblSerialNumber.Text
        End Get
        Set(ByVal value As String)
            lblSerialNumber.Text = value
        End Set
    End Property

    Private Sub UpdateStatus()
        setbackcolor(FIO0, 0)
        setbackcolor(FIO1, 1)
        setbackcolor(FIO2, 2)
        setbackcolor(FIO3, 3)
        setbackcolor(FIO4, 4)
        setbackcolor(FIO5, 5)
        setbackcolor(FIO6, 6)
        setbackcolor(FIO7, 7)
        setbackcolor(EIO0, 8)
        setbackcolor(EIO1, 9)
        setbackcolor(EIO2, 10)
        setbackcolor(EIO3, 11)
        setbackcolor(EIO4, 12)
        setbackcolor(EIO5, 13)
        setbackcolor(EIO6, 14)
        setbackcolor(EIO7, 15)
        setbackcolor(CIO0, 16)
        setbackcolor(CIO1, 17)
        setbackcolor(CIO2, 18)
        setbackcolor(CIO3, 19)

    End Sub

    Private Sub setbackcolor(ByRef cb As RadioButton, ByVal Idx As Integer)
        If _Config.Tables(0).Rows(Idx).Item("Active") Then
            cb.Checked = True
            If _Status(Idx) Then
                cb.BackColor = Color.Red
            Else
                cb.BackColor = Color.LightGreen
            End If
        Else
            cb.Checked = False
            cb.BackColor = Color.LightGray
        End If
        If ShowDescription Then
            cb.Text = Config.Tables(0).Rows(Idx).Item("Description")
        Else
            cb.Text = cb.Tag
        End If
    End Sub

#Region "Click Events on the display"

    Private Sub FIO0_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FIO0.Click
        RaiseEvent PortSelected(0)
    End Sub

    Private Sub FIO1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FIO1.Click
        RaiseEvent PortSelected(1)
    End Sub

    Private Sub FIO2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FIO2.Click
        RaiseEvent PortSelected(2)
    End Sub

    Private Sub FIO3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FIO3.Click
        RaiseEvent PortSelected(3)
    End Sub

    Private Sub FIO4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FIO4.Click
        RaiseEvent PortSelected(4)
    End Sub

    Private Sub FIO5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FIO5.Click
        RaiseEvent PortSelected(5)
    End Sub

    Private Sub FIO6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FIO6.Click
        RaiseEvent PortSelected(6)
    End Sub

    Private Sub FIO7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FIO7.Click
        RaiseEvent PortSelected(7)
    End Sub

    Private Sub EIO0_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EIO0.Click
        RaiseEvent PortSelected(8)
    End Sub

    Private Sub EIO1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EIO1.Click
        RaiseEvent PortSelected(9)
    End Sub

    Private Sub EIO2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EIO2.Click
        RaiseEvent PortSelected(10)
    End Sub

    Private Sub EIO3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EIO3.Click
        RaiseEvent PortSelected(11)
    End Sub

    Private Sub EIO4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EIO4.Click
        RaiseEvent PortSelected(12)
    End Sub

    Private Sub EIO5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EIO5.Click
        RaiseEvent PortSelected(13)
    End Sub

    Private Sub EIO6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EIO6.Click
        RaiseEvent PortSelected(14)
    End Sub

    Private Sub EIO7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EIO7.Click
        RaiseEvent PortSelected(15)
    End Sub

    Private Sub CIO0_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CIO0.Click
        RaiseEvent PortSelected(16)
    End Sub

    Private Sub CIO1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CIO1.Click
        RaiseEvent PortSelected(17)
    End Sub

    Private Sub CIO2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CIO2.Click
        RaiseEvent PortSelected(18)
    End Sub
    Private Sub CIO3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CIO3.Click
        RaiseEvent PortSelected(19)
    End Sub

    Private Sub lblSerialNumber_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblSerialNumber.Click
        ShowDescription = Not ShowDescription
        UpdateStatus()
    End Sub
#End Region


    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub


End Class
